﻿
/// <reference path="../Ext4.0/ext-all.js" />
setTimeout(function () {
    Ext.get('loading').remove();
    Ext.get('loading-mask').fadeOut({ remove: true });
}, 1000);

Ext.BLANK_IMAGE_URL = "image/s.gif";
Ext.QuickTips.init();


Ext.require([
    'Ext.data.*',
    'Ext.tip.QuickTipManager',
    'Ext.window.MessageBox'
]);

var fields = [
   {
       name: "ID", type: "string"
   }, {
       name: "PlaceName", type: "string"
   }, {
       name: "ParentID", type: "string"
   }, {
       name: "ParentName", type: "string"
   }, {
       name: "Description", type: "string"
   }, {
       name: "PlaceType", type: "string"
   }];

Ext.define('Users', {
    extend: 'Ext.data.Model',
    fields: fields
});
/*******************************************/
/*添加修改时所需变量**/
var ParentID = "";
var ParentName = "";


/*******************************************/

var pageSize = 16;

var StorePage = Ext.create('Ext.data.Store', {
    pageSize: pageSize,
    fields: fields,
    model: 'ForumThread',
    remoteSort: false,
    proxy: {
        type: 'ajax',
        url: "ExamPlaceMag.aspx?action=BindGrid",
        actionMethods: 'post',
        reader: {
            type: 'json',
            root: 'data',
            totalProperty: "totalCount"
        }
    }
});


StorePage.load({ params: { start: 0, limit: pageSize} });
StorePage.on("beforeload", function () {

    Ext.apply(StorePage.proxy.extraParams,
         {
             MenuTitle: Ext.getCmp('MenuTitle').getValue()
         }

         );

});
//--------------------------------------------------列选择模式

var sm = Ext.create('Ext.selection.CheckboxModel', {
    dataIndex: "ID"
});

onAddClick = function onAddClick() {
    addWin.show();
}
var row = "";
onEditClick = function onEditClick() {
  
     row = Ext.getCmp("grid").getSelectionModel().getSelection();
    if (row.length == 0) {
        Ext.Msg.alert("提示信息", "您没有選中任何行!");
    }
    else if (row.length > 1) {
        Ext.Msg.alert("提示信息", "對不起只能選擇一个!");
    } else if (row.length == 1) {
        EditWin.show();
    }

}

function onDeleteClick() {
    var row = Ext.getCmp("grid").getSelectionModel().getSelection();
    if (row.length == 0) {
        Ext.Msg.alert("提示信息", "请您至少選擇一个!");
    }
    else {
        Ext.Msg.confirm("提示!", "您确定要删除该菜单信息吗?", function (btn) {
            if (btn == "yes") {
                DeleteInfoFn(row);
            }
            else {

            }
        })
    }
}


Ext.onReady(function () {
    var queryPnl = Ext.create('Ext.form.Panel', {
        id: 'frm',
        collapsible: true,
        border: true,
        labelWidth: 70,
        autoHeight: true,
        layout: 'anchor',
        defaults: { autoWidth: true },
        items: [
            {
                xtype: 'textfield',
                id: 'MenuTitle',
                fieldLabel: '菜單名稱',
                name: 'MenuTitle'
            }],
        buttons: [{
            text: '查询',
            id: 'btnSearch',
            minWidth: 60,
            handler: queryInfo
        }],
        renderTo: Ext.getBody()
    });


    var pluginExpanded = true;
    var grid = Ext.create('Ext.grid.Panel', {
        autoScroll:true,
        selModel: sm,
        id: "grid",
        store:StorePage,
        height: document.documentElement.clientHeight - 80,
        autoHeight: true,
        iconCls: 'icon-grid',
        columns: [

                { header: 'ID', dataIndex: 'ID' },
                { header: '名称', dataIndex: 'PlaceName' },
                { header: '上级', dataIndex: 'ParentID',hidden:true },
                { header: '上级名称', dataIndex: 'ParentName' },
                { header: '描述', dataIndex: 'Description' },
                { header: '类型', dataIndex: 'PlaceType' }
            ],
        dockedItems: [{
            xtype: 'toolbar',
            items: [{
                iconCls: 'addicon',
                text: '新增',
                scope: this,
                handler: onAddClick
            }, {
                iconCls: 'editicon',
                text: '修改',
                scope: this,
                handler: onEditClick
            }, {
                iconCls: 'deleteicon',
                text: '删除',
                itemId: 'delete',
                scope: this,
                handler: onDeleteClick
            }]
        }],
        bbar: Ext.create('Ext.PagingToolbar', {
            store: StorePage,
            pageSize: pageSize,
            displayInfo: true,
            displayMsg: '分页 {0} - {1} of {2}',
            emptyMsg: "No topics to display",
            prevText: "上一页",
            nextText: "下一页",
            refreshText: "刷新",
            lastText: "最后一页",
            firstText: "第一页",
            beforePageText: "当前页",
            afterPageText: "共{0}页"
        }),
        renderTo: Ext.getBody()

    });



    function queryInfo(x) {
        var MenuTitle = Ext.getCmp('frm').getComponent('MenuTitle').getValue();
        StorePage.load({
            params: { MenuTitle: MenuTitle }
        });
    }


});